package net.dgi.common.match;

/**
 * Viva IntelliJ IDEA.
 * Author: Deian Date: Sep 30, 2010 Time: 11:39:32 PM
 *
 * Match Engine is an experimental execution queue engine that will automatically match data to any available functions
 * The data will be recycled and transformed until there are no more functions to match it or reaches maximum number of passes
 */
public interface MatchEngine {
    /**
     * Requests shutdown from all internal threads. If there are clients waiting for result they might receive InterruptedException
     */
    void requesShutdown();

    /**
     * NonBlocking! Drop data in the engine and it will process the data until exhaust all available functions.
     * the result can be extracted with poll.  Awakes the threads to process it
     *
     * @param object Object to process
     */
    void add(Object object);

    /**
     * Blocking method! drops the data into the engine and blocks until we get result
     *
     * @param object Object to processing queue and awakes the threads to process it
     * @return Object result of the processing
     * @throws Throwable
     */
    Object request(Object object) throws Throwable;

    /**
     * Add functionality to the engine and awakes all threads!
     *
     * @param function
     */
    void addFunctions(Object function);

    /**
     * Blocking method. Get response from the engine
     *
     * @return Object result of the processing
     * @throws Throwable
     */
    Object poll() throws Throwable;

    /**
     *
     * @return how many object are pending to be extracted as result
     */
    int size();
}
